package test02;




public class Solution {
    public ListNode detectCycle(ListNode head) {
        if(head == null ) return null;
        ListNode slow = head;
        ListNode fast = head;
        while(slow != fast) {
            slow = slow.next;
            fast = fast.next.next;
        }
        slow = head;
        while(slow != fast) {
            if(slow == null || fast == null) return null;
            slow = slow.next;
            fast = fast.next;
        }
        return slow;
    }
}